package com.tedu.egweibodemo.controller;

import com.tedu.egweibodemo.base.response.JsonResult;
import com.tedu.egweibodemo.base.response.StatusCode;
import com.tedu.egweibodemo.mapper.CommentMapper;
import com.tedu.egweibodemo.pojo.dto.CommentAddParam;
import com.tedu.egweibodemo.pojo.entity.Comment;
import com.tedu.egweibodemo.pojo.vo.CommentVO;
import com.tedu.egweibodemo.pojo.vo.UserVO;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpSession;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/v1/comment")
@Tag(name = "评论模块")
public class CommentController {
    @Autowired
    private CommentMapper commentMapper;
    @PostMapping("/insert")
    public JsonResult insert(@RequestBody CommentAddParam commentAddParam , HttpSession session){
        UserVO userVO = (UserVO) session.getAttribute("user");
//        if (userVO == null) {
//            return new JsonResult(StatusCode.NOT_LOGIN);
//        }
        Comment comment = new Comment();
        BeanUtils.copyProperties(commentAddParam ,comment);
        comment.setCreateTime(new Date());
        comment.setUserId(userVO.getId());
        int num  = commentMapper.insert(comment);
        return JsonResult.success();
    }
    @GetMapping("/list")
    public JsonResult list(Long weiboId){
        List<CommentVO> list =  commentMapper.select(weiboId);
        return JsonResult.success(list);
    }
}
